FROM alpine:3.13 as compilingqB

#compiling qB

ARG  LIBTORRENT_VER=1.2.13
ARG  QBITTORRENT_VER=4.3.5


RUN  apk add --no-cache ca-certificates make g++ gcc qt5-qtsvg-dev boost-dev qt5-qttools-dev file \
&&   mkdir /qbtorrent  \
&&   wget -P /qbtorrent https://github.com/arvidn/libtorrent/releases/download/v${LIBTORRENT_VER}/libtorrent-rasterbar-${LIBTORRENT_VER}.tar.gz   \
#&&   wget -P /qbtorrent https://github.com/arvidn/libtorrent/releases/download/libtorrent-${LIBTORRENT_VER}/libtorrent-rasterbar-${LIBTORRENT_VER}.tar.gz   \
#&&   wget -P /qbtorrent https://github.com/arvidn/libtorrent/releases/download/libtorrent-`echo "$LIBTORRENT_VER"|sed 's#\.#_#g'`/libtorrent-rasterbar-${LIBTORRENT_VER}.tar.gz   \
#&&   wget -P /qbtorrent https://github.com/arvidn/libtorrent/releases/download/libtorrent_`echo "$LIBTORRENT_VER"|sed 's#\.#_#g'`/libtorrent-rasterbar-${LIBTORRENT_VER}.tar.gz   \
&&   tar  -zxvf  /qbtorrent/libtorrent-rasterbar-${LIBTORRENT_VER}.tar.gz   -C    /qbtorrent  \
&&   cd  /qbtorrent/libtorrent-rasterbar-${LIBTORRENT_VER} \
&&   if [ "$(uname -m)" = "x86_64" ];then host=x86_64-alpine-linux-musl;elif [ "$(uname -m)" = "aarch64" ];then host=aarch64-alpine-linux-musl;elif [ "$(uname -m)" = "armv7l" ];then host=armv7-alpine-linux-musleabihf; fi  \
&&   echo $host   \
&&   ./configure  CXXFLAGS="-std=c++14" --host=$host  \
&&   make install-strip -j2 \
#qBittorrent
&&   wget  -P /qbtorrent  https://github.com/qbittorrent/qBittorrent/archive/release-${QBITTORRENT_VER}.zip  \
&&   unzip   /qbtorrent/release-${QBITTORRENT_VER}.zip  -d    /qbtorrent \
&&   cd  /qbtorrent/qBittorrent-release-${QBITTORRENT_VER} \
#
&&   ./configure    --disable-gui --host=$host \
&&   make install  -j2 \
&&   ldd /usr/local/bin/qbittorrent-nox   |cut -d ">" -f 2|grep lib|cut -d "(" -f 1|xargs tar -chvf /qbtorrent/qbittorrent.tar  \
&&   mkdir /qbittorrent   \
&&   tar  -xvf /qbtorrent/qbittorrent.tar   -C  /qbittorrent   \
&&   cp --parents /usr/local/bin/qbittorrent-nox  /qbittorrent


 # docker qB


FROM alpine:3.13

ARG  S6_VER=2.2.0.3

ENV TRACKERSAUTO=YES
ENV TZ=Asia/Shanghai
ENV WEBUIPORT=8989
ENV UID=0
ENV GID=0
ENV UMASK=022

COPY root /
COPY --from=compilingqB  /qbittorrent  /

# install bash curl caddy tzdata s6 overlay python3 shadow
RUN  if [ "$(uname -m)" = "x86_64" ];then s6_arch=amd64;elif [ "$(uname -m)" = "aarch64" ];then s6_arch=aarch64;elif [ "$(uname -m)" = "armv7l" ];then s6_arch=arm; fi  \
&&   wget --no-check-certificate https://github.com/just-containers/s6-overlay/releases/download/v${S6_VER}/s6-overlay-${s6_arch}.tar.gz  \
&&   tar -xvzf s6-overlay-${s6_arch}.tar.gz  \
&&   rm s6-overlay-${s6_arch}.tar.gz   \
&&   apk add --no-cache bash curl ca-certificates  tzdata  python3 shadow \
&&   rm -rf /var/cache/apk/*   \
#create qbittorrent user
&&  useradd -u 1000 -U -d /config -s /bin/false   qbittorrent   \
&&  usermod -G users qbittorrent   \
#
&&   chmod a+x  /usr/local/qbittorrent/updatetrackers.sh  \
&&   chmod a+x  /usr/local/bin/qbittorrent-nox


VOLUME /Downloads /config
EXPOSE 8989  6881  6881/udp
ENTRYPOINT [ "/init" ]
